//
// Created by Administrator on 2024/5/4.
//

#include <iostream>
#include <algorithm>
#include "linkedListUtil.h"

Node *reverseLinkedList(Node *h);

using namespace std;


int main()
{
    vector<int> l{1,2,3,4,5};
    Node *head = build(l);
    printLinkedList(head);
    head = reverseLinkedList(head->next);
    printLinkedList(head);
    return 0;
}

Node *reverseLinkedList(Node *h)
{
    Node *pre = nullptr;
    Node *cur = h;
    while(h)
    {
        cur=h->next;
        h->next=pre;
        pre=h;
        h=cur;
    }
    pre = new Node{0,pre};
    return pre;
}
